package com.wanshi.cloud.service.impl;

import com.wanshi.cloud.client.OrderClient;
import com.wanshi.cloud.entity.Orders;
import com.wanshi.cloud.entity.User;
import com.wanshi.cloud.mapper.UserMapper;
import com.wanshi.cloud.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanshi.cloud.utils.base.Page;
import com.wanshi.cloud.utils.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 顽石教育-www.wanshi.com
 * @since 2021-09-02
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private OrderClient orderClient;

    @Override
    public Result findById(Integer id) {
        User user = this.getById(id);

        //服务调用给user设置订单
        List<Orders> list = orderClient.findByUserId(id);
        user.setOrders(list);
        return Result.ok(user);
    }

    @Override
    public Result findAll() {
        List<User> list = this.list();
        return Result.ok(list);
    }

    @Override
    public Result findByPage(Integer page, Integer size) {
        Page p = new Page(page,size);
        baseMapper.selectPage(p, null);
        return Result.ok(p);
    }
}
